<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Java实训课程 -记账</title>
  <!--[if lt IE 9]>
  <script src="libs/html5shiv.min.js"></script>
  <script src="libs/respond.min.js"></script>
  <![endif]-->
  <script src="libs/jquery-1.12.1.min.js"></script>
  <link href="libs/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
  <script src="libs/bootstrap-3.3.6/js/bootstrap.min.js"></script>
  <script  src="libs/handlebars.min.js"></script>
  <script  src="libs/js.cookie-2.1.0.min.js"></script>
</head>
<body>
  <div class="container">
    <div class="row">
      <div class="page-header">
        <h2>存取记账</h2>
      </div>
    </div>
    <div class="row">
      <div class="col-md-8">
        <ul class="nav nav-pills">
          <li role="presentation" class="active"><a href="index.html">首页</a></li>
          <li role="presentation"><a href="add1.html">添加收入</a></li>
          <li role="presentation"><a href="add2.html">添加支出</a></li>
          <li role="presentation"><a href="query.html">查询</a></li>
          <li role="presentation"><a href="statis.html">统计</a></li>
        </ul>
      </div>
        <div class="col-md-4" id="search-box-archive"></div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <hr/>
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <hr  />
      </div>
    </div>
  </div>
  <div class="container">
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-primary">
          <div class="panel-heading">最近浏览（当前用户）</div>
          <div class="panel-body" id="nick"></div>
        </div>
      </div>
    </div>
      <div class="col-md-6">
        <div class="panel panel-warning">
          <div class="panel-heading"><p>一周内的收入</p></div>
          <div class="panel-body"><h1 id="text1" ></h1></div>
        </div>
      </div>
      <div class="col-md-6">
        <div class="panel panel-warning">
          <div class="panel-heading"><p>一周内的支出</p></div>
          <div class="panel-body"><h1 id="text2" ></h1></div>
        </div>
      </div>
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-success">
          <div class="panel-heading">最近的四笔收入</div>
          <div class="panel-body" id="list1"></div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-12">
        <div class="panel panel-warning">
          <div class="panel-heading">最近的四笔支出</div>
          <div class="panel-body" id="list2"></div>
        </div>
      </div>
    </div>
    </div>
  <script id="template" type="text/x-handlebars-template">
    {{#each item}}
    <div class="panel panel-default col-md-3">
      <div class="panel-body">
      <dl>
        <dt>时间</dt><dd>{{date_time}}</dd>
        <dt>地点</dt><dd>{{place}}</dd>
        <dt>金额</dt><dd>{{money_in}}</dd>
        <dt>类别</dt><dd>{{kind}}</dd>
      <dl>
      </div>
    </div>
    {{/each}}
  </script>
  <script id="template1" type="text/x-handlebars-template">
    {{#each item}}
    <div class="panel panel-default col-md-3">
      <div class="panel-body">
      <dl>
        <dt>时间</dt><dd>{{date_time}}</dd>
        <dt>地点</dt><dd>{{place}}</dd>
        <dt>金额</dt><dd>{{money_out}}</dd>
        <dt>类别</dt><dd>{{kind}}</dd>
      <dl>
      </div>
    </div>
    {{/each}}
  </script>
  <script type="text/javascript" >
    $(function(){
    	$.getJSON('queryuser.action',function(res){
    	    console.log(res);
    		$('#text1').text(res.si);
    		$('#text2').text(res.su);
    	})
    	$.getJSON('querynick.action',function(res){
    	    console.log(res);
    		$('#nick').text(res.si);
    	})
    	$.getJSON('queryday.action',function(res){
    	    console.log(res);
    	    var data={'item':res};
    	    var t=Handlebars.compile($('#template').html());
    	    $('#list1').html(t(data));
    	})
    	$.getJSON('queryday.action',function(res){
    	    console.log(res);
    	    var data={'item':res};
    	    var t=Handlebars.compile($('#template1').html());
    	    $('#list2').html(t(data));
    	})
    })
    if (!Cookies.get("user")){
    	window.location.href="login.html";
    }
  </script>
</body>
</html>
